package com.yty.system.oauth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yty.system.oauth.entity.SysUser;
import com.yty.system.oauth.mapper.UserMapper;
import com.yty.system.oauth.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yegang
 * @since 2022-06-15
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, SysUser> implements IUserService {

    @Autowired
    @Qualifier("taskExecutor1")
    private TaskExecutor taskExecutor;

    @Override
    public SysUser findByUserName(String username) {
        return getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getUsername,username));
    }

    @Override
    public void insert(SysUser sysUser) {
        SysUser user = findByUserName(sysUser.getUsername());
        if (user != null) {
            throw new RuntimeException("用户已存在");
        }
        save(sysUser);
    }
}
